import os

import pytest

from common.webdriver_factory import WebdriverFactory
from utils.read_env import read_env


@pytest.fixture(scope="session")
def env_dict():
    """获得环境变量字典"""
    env_path = os.path.join(os.path.dirname(__file__), '.env')
    env_dict = read_env(env_path)
    return env_dict


@pytest.fixture(scope="session", autouse=True)
def driver(env_dict):
    """初始化driver"""
    driver = WebdriverFactory.get_webdriver()
    return driver


@pytest.fixture(scope="session", autouse=True)
def close_driver(driver):
    """会话级后置清理工作"""
    yield
    driver.close()
